package com.shaoshaohuo.app.view;
import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.PopupWindow;

import java.util.ArrayList;
import java.util.List;

import com.shaoshaohuo.app.R;
/**
 * Created by yusonglin on 2015/7/14.
 * Description:
 */
public class TimePopwindow implements View.OnClickListener {

    private Context context;
    private PopupWindow hintPopWinwow;

    private WheelView mWheelView1;
    private WheelView mWheelView2;
    private WheelView mWheelView3;

    private Button mCancelButton;
    private Button mOkButton;

    private OnSelectTimeListener onSelectTimeListener;

    public TimePopwindow(Context context){
        this.context = context;
        initView();
    }

    private void initView(){
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        final View contentView = inflater.inflate(R.layout.popwindow_layout_bottom_select, null, false);
        hintPopWinwow = new PopupWindow(contentView, WindowManager.LayoutParams.MATCH_PARENT,
                WindowManager.LayoutParams.WRAP_CONTENT, true);
        hintPopWinwow.setOutsideTouchable(true);
        hintPopWinwow.setBackgroundDrawable(new BitmapDrawable());
        hintPopWinwow.setAnimationStyle(R.style.Anim_Dialog_Bottom);

        mWheelView1 = (WheelView) contentView.findViewById(R.id.wv1);
        mWheelView2 = (WheelView) contentView.findViewById(R.id.wv2);
        mWheelView3 = (WheelView) contentView.findViewById(R.id.wv3);

        mOkButton = (Button) contentView.findViewById(R.id.button_ok);
        mCancelButton = (Button) contentView.findViewById(R.id.button_cancel);

        List<Object> list = new ArrayList<>();
        list.add("8:00-10:00");
        list.add("9:00-11:00");
        list.add("10:00-12:00");
        list.add("11:00-13:00");
        list.add("12:00-14:00");
        list.add("13:00-15:00");
        list.add("14:00-16:00");
        list.add("15:00-17:00");
        list.add("16:00-18:00");
        list.add("17:00-19:00");
        list.add("18:00-20:00");

        mWheelView1.setClumnCount(1);

        mWheelView1.setItems(list);

        mWheelView2.setVisibility(View.GONE);
        mWheelView3.setVisibility(View.GONE);


        mOkButton.setOnClickListener(this);
        mCancelButton.setOnClickListener(this);

    }

    public void showLocation(View view){
        hintPopWinwow.showAtLocation(view, Gravity.BOTTOM, 0, 0);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
        case R.id.button_ok:
            hintPopWinwow.dismiss();
            if(onSelectTimeListener != null){
                onSelectTimeListener.onSelectTime((String) mWheelView1.getSeletedItem());
            }
            break;
        case R.id.button_cancel:
            hintPopWinwow.dismiss();
            break;
        }
    }

    public void setOnSelectDateListener(OnSelectTimeListener onSelectDateListener){
        this.onSelectTimeListener = onSelectDateListener;
    }

    public interface OnSelectTimeListener{
        void onSelectTime(String time);
    }

}
